# Maintainer: Andrei Zavada <andrei.zavada@tiot.jp>
pkgname=riak
pkgver=3.0.9
_pkgtag="riak-3.0.9-tiot"
pkgrel=0
pkgdesc="Riak is a distributed KV database"
url="https://github.com/TI-Tokyo/riak"
arch="aarch64 ppc64le x86 x86_64"
license="Apache-2.0"
depends="bash"
makedepends="erlang22 erlang22-dev erlang22-dialyzer cmake autoconf automake libtool linux-pam-dev"
subpackages="$pkgname-openrc"
source="
	riak-$_pkgtag.tar.gz::https://github.com/TI-Tokyo/riak/archive/refs/tags/$_pkgtag.tar.gz
	riak.initd
	"
builddir="$srcdir/riak-$_pkgtag"

build() {
	git config --global url."https://".insteadOf git://
	make rel-alpine
}

check() {
	make test
}

package() {
	reldir="$PWD/rel/riak"
	mkdir -p "$pkgdir/usr/bin"
	mkdir -p "$pkgdir/usr/sbin"
	mkdir -p "$pkgdir/usr/lib/riak"
	mkdir -p "$pkgdir/var/lib/riak"
	mkdir -p "$pkgdir/var/log/riak"
	mkdir -p "$pkgdir/etc/riak"
	mkdir -p "$pkgdir/run/riak"
	for f in riak-admin riak-chkconfig riak-debug riak-repl; do
	    cp "$reldir/bin/$f" "$pkgdir/usr/bin"
	done
	cp "$reldir/usr/bin/riak" "$pkgdir/usr/sbin"
	install "$reldir/etc/riak.conf" "$pkgdir/etc/riak/riak.conf"
	cp -R "$reldir"/bin        "$pkgdir/usr/lib/riak"
	cp -R "$reldir"/etc/*      "$pkgdir/etc/riak"
	cp -R "$reldir"/erts-*     "$pkgdir/usr/lib/riak"
	cp -R "$reldir"/share      "$pkgdir/usr/lib/riak"
	cp -R "$reldir"/releases   "$pkgdir/usr/lib/riak"
	cp -R "$reldir"/lib        "$pkgdir/usr/lib/riak"
	cp -R "$reldir"/data/*     "$pkgdir/var/lib/riak"

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
}

sha512sums="
5f726666af5672c570d99ef2f2e99bbda4f7832ec2701dac293b75ea517fcd92edabb2c2154654974daec74c5284455d312fa6bbe12aa13de64d8e13a7ddb1f3  riak-riak-3.0.9-tiot.tar.gz
de9a0cb7aaa81588735e3e995523743a34bda8fadb502b08900af94f99fb1b1bbb122b484fc3add7215ae6c2016bd1b381873ec836d9cabc7e1c987e59d823ed  riak.initd
"
